<@>layout("/common/default.html"){
<style>
    .select2-container .select2-selection--multiple {
        min-height: 38px;
    }

    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 36px;
    }

    .select2-container .select2-search--inline .select2-search__field {
        margin-top: 10px;
    }
</style>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <span lay-separator="">/</span>
        <a href="">邮箱管理</a>
        <span lay-separator="">/</span>
        <a><cite>邮件详情</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="x-body">
    <form class="layui-form" id="email-data" action="${ctxPath}/email/send" method="post">
        <div class="layui-row">
            <div class="layui-form-item">
                <label class="layui-form-label">收件人：</label>
                <div class="layui-input-block" style="width: 65.5%;">
                    <div class="layui-form-mid layui-word-aux"> ${mailHistory.name}</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">主题：</label>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux"> ${mailHistory.title}</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容：</label>
                <div class="layui-input-block">
                    <script id="container" name="content" type="text/plain" style="width:90.55%;height:400">
                        ${mailHistory.content}

                    </script>
                </div>
            </div>

        </div>
    </form>
</div>
<div>

</div>
<script>

    layui.use('upload', function () {
        var upload = layui.upload;

    });

    var ue = UE.getEditor('container', {
        autoHeight: false,
        scaleEnabled:true,//设置不自动调整高度
        toolbars: [
            [
                'fullscreen', //全屏
            ]
        ]
    });
    ue.ready(function () {
        ue.setHeight(400);
    });


    $(function () {
        var code = '${code!}';
        var msg = '${message!}';
        if (msg) {
            $.msg(msg, function () {
            }, code);
        }
        $('#sjr').select2({
            placeholder: "请选择收件人",
            width: '100%',
            language: 'zh-CN',
            closeOnSelect: true,
            multiple: true,
            ajax: {
                url: '${ctxPath}/ajax/email/userMail/select2',
                dataType: 'json',
                delay: 250,
                data: function (params) {
                    return {
                        id: params.id,
                        q: params.term, // search term
                        pageNo: params.page
                    };
                },
                processResults: function (data, params) {
                    params.page = params.page || 1;
                    return {
                        results: data.items,
                        pagination: {
                            more: (params.page * 10) < data.totalCount
                        }
                    };
                },
                cache: false
            },
            escapeMarkup: function (markup) {
                return markup;
            },
            minimumInputLength: 0,
            //格式化下拉列表的数据
            templateResult: function (obj) {
                if (!obj.id) {
                    return obj.text + obj.mail;
                }
                return obj.name + obj.mail;
            },
            templateSelection: function (obj) {
                var name = "";
                var mail = "";
                if (obj.mail) {
                    mail = obj.mail;
                }
                if (obj.id) {
                    name = obj.name + mail;
                } else {
                    name = obj.text + mail;
                }
                return name || obj.text + mail;
            }
        }).on("select2:select", function (e) {
            var userId = e.params.data.id;
            var mail = e.params.data.mail;
            var mailUserIds = $('#mailUserIds').val();
            var mails = $('#mails').val();
            if (mailUserIds) {
                $('#mailUserIds').val(mailUserIds + "," + userId);
                $('#mails').val(mails + "," + mail);
            } else {
                $('#mailUserIds').val(userId);
                $('#mails').val(mail);
            }

        }).on("select2:unselect", function (e) {
            var mailUserIds = $('#mailUserIds').val();
            var mails = $('#mails').val();
            mailUserIds = removeStr(mailUserIds, e.params.data.id);
            mails = removeStr(mails, e.params.data.mail);
            $('#mailUserIds').val(mailUserIds);
            $('#mails').val(mails);
        });

        $('#csr').select2({
            placeholder: "请选择抄送人",
            width: '100%',
            language: 'zh-CN',
            closeOnSelect: true,
            multiple: true,
            ajax: {
                url: '${ctxPath}/ajax/email/userMail/select2',
                dataType: 'json',
                delay: 250,
                data: function (params) {
                    return {
                        id: params.id,
                        q: params.term, // search term
                        pageNo: params.page
                    };
                },
                processResults: function (data, params) {
                    params.page = params.page || 1;
                    return {
                        results: data.items,
                        pagination: {
                            more: (params.page * 10) < data.totalCount
                        }
                    };
                },
                cache: false
            },
            escapeMarkup: function (markup) {
                return markup;
            },
            minimumInputLength: 0,
            //格式化下拉列表的数据
            templateResult: function (obj) {
                if (!obj.id) {
                    return obj.text + obj.mail;
                }
                return obj.name + obj.mail;
            },
            templateSelection: function (obj) {
                var name = "";
                var mail = "";
                if (obj.mail) {
                    mail = obj.mail;
                }
                if (obj.id) {
                    name = obj.name + mail;
                } else {
                    name = obj.text + mail;
                }
                return name || obj.text + mail;
            }
        }).on("select2:select", function (e) {
            var userId = e.params.data.id;
            var mail = e.params.data.mail;
            var mailUserIds = $('#copyUserIds').val();
            var mails = $('#copyMails').val();
            if (mailUserIds) {
                $('#copyUserIds').val(mailUserIds + "," + userId);
                $('#copyMails').val(mails + "," + mail);
            } else {
                $('#copyUserIds').val(userId);
                $('#copyMails').val(mail);
            }

        }).on("select2:unselect", function (e) {
            var mailUserIds = $('#copyUserIds').val();
            var mails = $('#copyMails').val();
            mailUserIds = removeStr(mailUserIds, e.params.data.id);
            mails = removeStr(mails, e.params.data.mail);
            $('#copyUserIds').val(mailUserIds);
            $('#copyMails').val(mails);
        });
    });

    function addOrDelCopy(type) {
        if (type == '1') {
            $('#copyDiv').show();
            $('#addCopy').hide();
            $('#delCopy').show();
        } else {
            $('#copyDiv').hide();
            $('#addCopy').show();
            $('#delCopy').hide();
            $('#copyUserIds').val('');
            $('#copyMails').val('');
            $('#csr').html('');
        }

    }

    function subForm() {
        var mailUserIds = $('#mailUserIds').val();
        if (!mailUserIds) {
            $.msg("请选择收件人！", function () {
            }, 2);
        } else {
            $('#email-data').submit();
        }
    }

    function delFile(id) {
        $.cajax('${ctxPath}/ajax/email/baseFile/del?id=' + id, null, function (r) {
            var code = r.code;
            var msg = r.msg;
            if (code == '1') {
                $('#' + id).remove();
                $.msg(msg, function () {
                }, code);
            } else {
                $.msg(msg, function () {
                }, 2);
            }
        });
    }
</script>
<@>}